<?php
/**
 * Created by PhpStorm.
 * User: lwt
 * Date: 4/26/19
 * Time: 8:21 PM
 */

namespace app\index\controller;

use think\Request;
use app\index\model\TracesourceModel;

class Tracesource
{
    /**
     * 添加更新經銷商追溯信息
     * @return \think\response\Json
     */
    public function addTraceSource(){
        $request = Request::instance();
        $result = [];
        $data = $request->post();
        $dealerMsg = dealerVerification($data["de_openid"]);
        if ($dealerMsg["code"] == 400){
            return json($dealerMsg);
        }
        $data["tds_time"] = time();
        $num = TraceSourceModel::addTraceSource($data);
        if ($num != 0){
            $result["code"] = 200;
            $result["msg"] = "添加经销商追溯成功！";
            return json($result);
        }else{
            $result["code"] = 200;
            $result["msg"] = "更新经销商追溯成功！";
            return json($result);
        }
    }

    /**
     * 根據商品ID查詢經銷商追溯信息
     * @return \think\response\Json
     */
    public function selectAllTraceSourceById(){
        $request = Request::instance();
        $data = $request->param();
        $content = array();
        $data = TraceSourceModel::selectAllTraceSourceById($data);
        
        return json($data);
    }
}